// const appId = wx.getAccountInfoSync().miniProgram.appId;
import { baseUrl } from "../config";
let app = "";
let noNeedLoginList=[]
export function request(apiData,headerInfo = undefined) {
    const { url:apiUrl, type:methodType, params} = apiData
    if(!app){
      app = getApp()
    }
    return new Promise((resolve, rejects) => {
        const uInfo = app.globalData.userInfo || {} ;
        const appOptions = app.globalData.appOptions || {} ;
        const headers = Object.assign({
          version:'2.1.1',
          authorization:uInfo.token?'Bearer '+uInfo.token:'',
          platform: 'wxApplet',
          appId:appOptions.appId
        },headerInfo || {})
        let requstConfig = {
            url: baseUrl + apiUrl,
            method: methodType || "GET",
            data: params,
            header: headers,
            success: res => {
                // wx.hideLoading()
                // res.header['Set-Cookie'] && app.globalData.cookie.push(res.header['Set-Cookie'])
                // if (res.data.code === -10) {//您已被限制登录，如有疑问请联系客服
                //     wx.reLaunch({
                //         url: '/pages/pullBlack/pullBlack'
                //     })
                // }
                resolve(res.data);
            },
            fail: res => {
                // wx.hideLoading()
                rejects(res);
            }
        };
        wx.request(requstConfig);
    });
}
